package com.deltabravomedia.theoldtoad.server;

import java.io.IOException;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class TransformItemsServlet extends HttpServlet {

    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    	PersistenceManager pm = PMF.get().getPersistenceManager();
    	
        String query = "select from " + Items.class.getName() + " order by date";
        List<Items> items = (List<Items>) pm.newQuery(query).execute();
        if (items.isEmpty()) {
        } else {
            for (Items item : items) {
		    	Item newItem = new Item (item.getType(), item.getName(), item.getCost(), item.getDescription(), 
		    			item.getRecommend(), true, item.getDate());
		    	pm.makePersistent(newItem);
            }
        }
    	pm.close();
    	
		resp.sendRedirect("/update.jsp");
	}
}
